package com.dongdongshop.controller;

import com.dongdongshop.data.Result;
import com.dongdongshop.enums.ResultEnums;
import com.dongdongshop.model.TbItemCat;
import com.dongdongshop.service.ItemCatService;
import com.dongdongshop.vo.CatVo;
import com.dongdongshop.vo.ItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("itemCat")
public class ItemCatController {
    @Autowired
    private ItemCatService itemCatService;
    //查询分类数据
    @PostMapping("TbItemCatshow")
    public Result TbItemCatshow(@RequestParam Long parentId){
        try {
            List<CatVo> list = itemCatService.query(parentId);
            return Result.response(ResultEnums.SUCCESS).setData(list);
        }catch (Exception e) {
            return Result.ER();
        }
    }

    //扣减库存
    @PostMapping("subStockCount")
    public Result subStockCount(@RequestBody List<ItemVo> itemVoList){
        itemCatService.subStockCount(itemVoList);
        return Result.OK();
    }
}
